package com.zidian.study.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zidian.student.trucks.R;
import com.zidian.study.bean.ActionPeopleBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by GongCheng on 2016/11/23.
 */

public class ActionPeopleListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<ActionPeopleBean.DataBean> dataList;

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_action_people,parent,false);

        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ItemViewHolder) {
            ((ItemViewHolder) holder).peopleName.setText(dataList.get(position).getStudentName());
            ((ItemViewHolder) holder).peopleClass.setText(dataList.get(position).getStudentClass());
        }
    }

    public void setData(List<ActionPeopleBean.DataBean> dataList){
        this.dataList = dataList;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return dataList == null ? 0 : dataList.size();
    }

    class ItemViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.people_name)
        TextView peopleName;
        @Bind(R.id.people_class)
        TextView peopleClass;

        public ItemViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
